package com.xing.controller;

import com.xing.bean.WeatherResponse;
import com.xing.service.RequestUrlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 请求的控制层
 *
 * @author: xingfuhao
 * @create: 2022-03-16 23:10
 */
@Controller
@RequestMapping("/requestUrl")
@Slf4j //lombok自带的日志插件
public class RequestUrlController {

    @Autowired
    private RequestUrlService requestUrlService;
    //返回的是json数据 ---实体类 WeatherResponse ---统一的 返回 响应状态码
    // 以后直接通过空格控制确认键盘，这样就省事啦，尽量不要用1⃣️，当然如果又习惯的话，可以用1的
    @RequestMapping("/cityId/{cityId}")
    @ResponseBody
    public WeatherResponse getWeatherResponseByCityId(@PathVariable("cityId") String cityId){
        log.info("cityId 是 ---"+cityId);
        //System.out.println(); 实际开发中基本不用这个
        //使用第三方接口 调用service
        WeatherResponse weatherResponse = requestUrlService.getWeatherResponseByCityId(cityId);
        return weatherResponse;
    }

}
